package com.jinzhi.jzweb.controller;


import java.util.*;

import com.jinzhi.jzweb.domain.PeixResumeCollectDO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.LeavingAMessageDO;
import com.jinzhi.jzweb.service.LeavingAMessageService;
import com.jinzhi.common.utils.Result;

/**
 * 
 * <pre>
 * 
 * </pre>
 * <small> 2021-07-03 14:32:04 | lance</small>
 */
@Slf4j
@Controller
@AllArgsConstructor
@RequestMapping("/jzweb/leavingAMessage")
public class LeavingAMessageController extends BaseController {
	@Autowired
	private LeavingAMessageService leavingAMessageService;
	
	@GetMapping()
	@RequiresPermissions("jzweb:leavingAMessage:leavingAMessage")
	String LeavingAMessage(){
	    return "jzweb/leavingAMessage/leavingAMessage";
	}



	@CrossOrigin
	@GetMapping("/leacingaMessaheSace")
	@ResponseBody
	public Result<?> resumeCollect(LeavingAMessageDO leavingAMessage) {
		leavingAMessage.setCreateTime(new Date());
		boolean b =leavingAMessageService.insert(leavingAMessage);
		if(b){
			return	Result.ok();
		}

		return Result.fail();
	}


	@CrossOrigin
	@GetMapping("/leacingaMessaheList")
	@ResponseBody
	public Result<?> leacingaMessaheList() {

		List<Map> list =leavingAMessageService.list();
		return 	Result.ok(list);

	}


	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:leavingAMessage:leavingAMessage")
	public Result<Page<LeavingAMessageDO>> list(LeavingAMessageDO leavingAMessageDTO){
		// 查询列表数据
		Page<LeavingAMessageDO> page = leavingAMessageService.selectPage(getPage(LeavingAMessageDO.class),
					leavingAMessageService.convertToEntityWrapper().orderBy("id", false));
		List list = new ArrayList();
		for (int i = 0; i < page.getRecords().size(); i++) {
				LeavingAMessageDO obj = (LeavingAMessageDO) page.getRecords().get(i);
			list.add(obj);
		}
		page.setRecords(list);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:leavingAMessage:add")
	String add(){
	    return "jzweb/leavingAMessage/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:leavingAMessage:edit")
	String edit(@PathVariable("id") Long id,Model model){
		LeavingAMessageDO leavingAMessage = leavingAMessageService.selectById(id);
		model.addAttribute("leavingAMessage", leavingAMessage);
	    return "jzweb/leavingAMessage/edit";
	}
	
	@Log("添加")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:leavingAMessage:add")
	public Result<String> save( LeavingAMessageDO leavingAMessage){
		leavingAMessageService.insert(leavingAMessage);
        return Result.ok();
	}
	
	@Log("修改")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:leavingAMessage:edit")
	public Result<String>  update( LeavingAMessageDO leavingAMessage){
		boolean update = leavingAMessageService.updateById(leavingAMessage);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:leavingAMessage:remove")
	public Result<String>  remove( Long id){
		leavingAMessageService.deleteById(id);
        return Result.ok();
	}
	
	@Log("批量删除")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:leavingAMessage:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		leavingAMessageService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
